<template>
  <!--父级路由和子级路由的选择-->
  <!-- <router-view v-if="$route.path !== '/treasure'"></router-view> -->

  <div class="treasure">
    <category @click-category="clickCategory" />
    <!-- 瀑布流 -->
    <div v-infinite-scroll="load" infinite-scroll-disabled="disabled">
      <wc-waterfall class="mt-5" :gap="20" :cols="4">
        <el-card
          class="rounded-2xl card"
          v-for="item in houses"
          :key="item.id"
          @click="clickCard(item.id)"
        >
          <img class="rounded-t-2xl" :src="item.img" />
          <p class="title">
            {{ item.title }}
          </p>
          <p class="des view-text">
            {{ item.des }}
          </p>
        </el-card>
      </wc-waterfall>
    </div>
  </div>
</template>

<script setup>
import Category from "@/components/Category.vue";
import { ref } from "vue";
import { getHouses, getHouseByCategoryId } from "@/api/house";
import { useRouter } from "vue-router";
import InfiniteList from "vue3-infinite-list";

const router = useRouter();
const houses = ref([]);
const clickCategory = async (id) => {
  console.log(id);
  await getHouseByCategoryId(id).then((res) => {
    houses.value = res.result;
  });
};
const load = () => {
  console.log("load");
};

const initHouse = async () => {
  await getHouses().then((res) => {
    houses.value = res.result;
  });
};
function clickCard(id) {
  router.push("/house/" + id);
}

initHouse();
</script>

<style lang="scss" scoped>
.view-text {
  /**
	思路：
	1.设置inline-block属相
	2.强制不换行
	3.固定高度
	4.隐藏超出部分
	5.显示“……”
  */
  display: inline-block;
  white-space: nowrap;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.treasure {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  color: #fff;
  padding: 20px 40px;
  height: 100%;
  overflow: auto;
  background-color: #ffffff;
  @media screen and (max-width: 510px) {
    padding: 20px;
  }
}
.card {
  transition: all 0.6s;
}
.card:hover {
  box-shadow: 0px 15px 30px rgba(0, 0, 0, 0.4);
}
.title {
  font-size: 15px;
  color: #666;
  margin: 4px;
}
.des {
  font-size: 13px;
  color: #9e9e9e;
  margin: 4px;
  padding-bottom: 6px;
}

.scrollbar-flex-content {
  display: flex;
  color: #000000;
  font-size: 12px;
}
.scrollbar-demo-item {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  width: 100px;
  height: 50px;
  margin: 10px;
  text-align: center;
  border-radius: 4px;
  transition: all 0.8s;
}
.scrollbar-demo-item:hover {
  box-shadow: 0px 10px 10px rgba(0, 0, 0, 0.4);
}
</style>
